#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std; 

/*
 * @param sum1 加数, 必须保证最后一个字符串以0结尾; 
 * @param sum2 被加数, 同样必须保证最后一个字符串必须以0结尾;
 * @return 返回只为指向结果的字符串;
 */

const char* sum(const char *sum1, const char* sum2){

	 if(sum1 == NULL )
		 return sum2; 
	 if(sum2 = NULL )
		 return sum1; 
	 int n1 = strlen(sum1); 
	 int n2 = strlen(sum2); 
	 int n = n1>n2?n1:n2; 
	 char *result = (char*)malloc(n+2);
	 result[n+1] = '\0';
	 int temp = 0; 
	 int jinwei = 0 ; 

	 while(n1>0 && n2 >0){
		temp = sum1[--n1] + sum2[--n2] + jinwei - '0'; 
		if(temp > '9'){
			jinwei = 1; 
			temp = temp -10; 
		}else{
			jinwei = 0; 
		}
		result[n--] = temp; 
	 }
	 while(n1>0){
		 temp = sum1[--n1] + jinwei; 
		 if(temp > '9' ){
			temp = temp - 10; 
			jinwei = 1; 
		 }
		 else{
			jinwei = 0; 
		 }
		 result[n--] = temp ; 
	 }
	 while(n2>0){
		 temp = sum1[--n2] + jinwei; 
		 if(temp > '9' ){
			temp = temp - 10; 
			jinwei = 1; 
		 }
		 else{
			jinwei = 0; 
		 }
		 result[n--] = temp ; 
	 }

	 return result; 

}
int main(){
	cout << sum("1234","2345") << endl;  
}
